<template>
  <div class="gooddetail">
    <h4>商品基本信息</h4>
    <div class="content trace-content" v-if="user==1">
      <div>
        <span>生产商地址: </span>
        <span>{{ good.from_address || good.address }}</span>
      </div>
      <div>
        <span>溯源码: </span>
        <span>{{ good.traceNumber }}</span>
      </div>
      <div>
        <span>商品名称: </span>
        <span>{{ good.name }}</span>
      </div>
      <div>
        <span>生产商: </span>
        <span>{{ good.from || good.produce }}</span>
      </div>
      <div>
        <span>生产地址: </span>
        <span>{{ good.produceLocation }}</span>
      </div>
      <div>
        <span>生产时间: </span>
        <span>{{ produceDate }}</span>
      </div>
      <div>
        <span>收货地址: </span>
        <span>{{ good.location }}</span>
      </div>
      <div>
        <span>到货时间: </span>
        <span>{{ date }}</span>
      </div>
      <div>
        <span>blockHash: </span>
        <span>{{ block_pro.blockHash }}</span>
      </div>
      <div>
        <span>blockNumber: </span>
        <span>{{ block_pro.blockNumber }}</span>
      </div>
      <div>
        <span>transactionHash: </span>
        <span>{{ block_pro.transactionHash }}</span>
      </div>
      <div>
        <span>timestamp: </span>
        <span>{{ good.timestamp }}</span>
      </div>
    </div>

    <div class="content trace-content" v-else-if="user != 2">
      <div>
        <span>生产商地址: </span>
        <span>{{ good.from_address || good.address }}</span>
      </div>
      <div>
        <span>溯源码: </span>
        <span>{{ good.traceNumber }}</span>
      </div>
      <div>
        <span>商品名称: </span>
        <span>{{ good.name }}</span>
      </div>
      <div>
        <span>生产商: </span>
        <span>{{ good.from || good.produce }}</span>
      </div>
      <div>
        <span>生产时间: </span>
        <span>{{ date }}</span>
      </div>
      <div>
        <span>生产地址: </span>
        <span>{{ good.location }}</span>
      </div>
      <div>
        <span>blockHash: </span>
        <span>{{ block_pro.blockHash }}</span>
      </div>
      <div>
        <span>blockNumber: </span>
        <span>{{ block_pro.blockNumber }}</span>
      </div>
      <div>
        <span>transactionHash: </span>
        <span>{{ block_pro.transactionHash }}</span>
      </div>
      <div>
        <span>timestamp: </span>
        <span>{{ good.timestamp }}</span>
      </div>
    </div>

    <div class="content trace-content" v-else>
      <div>
        <span>供应商地址: </span>
        <span>{{ good.from_address || good.address }}</span>
      </div>
      <div>
        <span>溯源码: </span>
        <span>{{ good.traceNumber }}</span>
      </div>
      <div>
        <span>商品名称: </span>
        <span>{{ good.name }}</span>
      </div>
      <div>
        <span>供应商: </span>
        <span>{{ good.from || good.produce }}</span>
      </div>
      <div>
        <span>发货地址: </span>
        <span>{{ good.DistributorLocation }}</span>
      </div>
      <div>
        <span>到货时间: </span>
        <span>{{ date }}</span>
      </div>
      <div>
        <span>到货地址: </span>
        <span>{{ good.location }}</span>
      </div>
      <div>
        <span>blockHash: </span>
        <span>{{ block_pro.blockHash }}</span>
      </div>
      <div>
        <span>blockNumber: </span>
        <span>{{ block_pro.blockNumber }}</span>
      </div>
      <div>
        <span>transactionHash: </span>
        <span>{{ block_pro.transactionHash }}</span>
      </div>
      <div>
        <span>timestamp: </span>
        <span>{{ good.timestamp }}</span>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  props:  ['good', 'block_pro', 'user'],
  computed:  {
    // 日期转换
    date() {
      if (this.good.timestamp) {
        return this.$dateTime(this.good.timestamp);
      } else {
        // 如果没有时间戳，返回一个默认值或提示
        return '未知';
      }
    },
    produceDate() {
      if (this.good.produceTime) {
        return this.$dateTime(parseInt(this.good.produceTime));
      } else {
        // 如果没有时间戳，返回一个默认值或提示
        return '未知';
      }
    }
  }
}
</script>

<style scoped>
.gooddetail table {
  border-spacing:  0;
}

.gooddetail .content {
  padding-left:  5%;
}

.gooddetail .content>div {
  height:  40px;
  width:  auto;
}
</style>